package usercontroller

import (
	"context"
	"gitee.com/go-mid/booter/bootservice"
	"gitee.com/go-mid/booter/web"
	"gitee.com/go-mid/infra/xlog"
	"gitee.com/go-mid/user/userservice"
)

// 查询
type GetUserAttrRequest struct {
	userservice.GetUserAttrReq
} //@name 获取用户表请求

func FactoryGetUserAttrRequest() web.HandleRequest {
	return new(GetUserAttrRequest)
}

//
// @Summary      获取用户表
// @Description  根据id获取用户表详情
// @Tags
// @Param        message	body		GetUserAttrRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.GetUserAttrRes} "响应"
// @Router       /user-attr/get [post]
func (m *GetUserAttrRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrController.GetUserAttr -->"
	res, err := userservice.DefaultUserService.GetUserAttr(ctx, &m.GetUserAttrReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.GetUserAttr err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 列表
type ListUserAttrRequest struct {
	userservice.ListUserAttrReq
} //@name 查询用户表请求

func FactoryListUserAttrRequest() web.HandleRequest {
	return new(ListUserAttrRequest)
}

//
// @Summary      查询用户表
// @Description  根据条件查询用户表详情
// @Tags
// @Param        message	body		ListUserAttrRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.ListUserAttrRes} "响应"
// @Router       /user-attr/list [post]
func (m *ListUserAttrRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrController.ListUserAttr -->"
	res, err := userservice.DefaultUserService.ListUserAttr(ctx, &m.ListUserAttrReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.ListUserAttr err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 添加
type AddUserAttrRequest struct {
	userservice.AddUserAttrReq
} //@name 添加用户表请求

func FactoryAddUserAttrRequest() web.HandleRequest {
	return new(AddUserAttrRequest)
}

//
// @Summary      添加用户表
// @Description  添加一条用户表记录
// @Tags
// @Param        message	body		AddUserAttrRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.AddUserAttrRes} "响应"
// @Router       /user-attr/add [post]
func (m *AddUserAttrRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrController.AddUserAttr -->"
	res, err := userservice.DefaultUserService.AddUserAttr(ctx, &m.AddUserAttrReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.AddUserAttr err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 修改
type UpdateUserAttrRequest struct {
	userservice.UpdateUserAttrReq
} //@name 修改用户表请求

func FactoryUpdateUserAttrRequest() web.HandleRequest {
	return new(UpdateUserAttrRequest)
}

//
// @Summary      修改用户表
// @Description  修改用户表记录
// @Tags
// @Param        message	body		UpdateUserAttrRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.UpdateUserAttrRes} "响应"
// @Router       /user-attr/update [post]
func (m *UpdateUserAttrRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrController.UpdateUserAttr -->"
	res, err := userservice.DefaultUserService.UpdateUserAttr(ctx, &m.UpdateUserAttrReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.UpdateUserAttr err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}

// 添加或修改
type UpsertUserAttrRequest struct {
	userservice.UpsertUserAttrReq
} //@name 添加或修改用户表请求

func FactoryUpsertUserAttrRequest() web.HandleRequest {
	return new(UpsertUserAttrRequest)
}

//
// @Summary      添加或修改用户表
// @Description  添加或修改用户表记录
// @Tags
// @Param        message	body		UpsertUserAttrRequest	true	"入参"
// @Success      200  {object}  web.ApiReturn{payload=userservice.UpsertUserAttrRes} "响应"
// @Router       /user-attr/upsert [post]
func (m *UpsertUserAttrRequest) Handle(ctx context.Context, c *bootservice.Context, clientInfo web.XFRMClientInfo, authInfo web.XFRMAuthInfo) (interface{}, error) {
	fun := "UserAttrController.UpsertUserAttr -->"
	res, err := userservice.DefaultUserService.UpsertUserAttr(ctx, &m.UpsertUserAttrReq)
	if err != nil {
		xlog.Warnf(ctx, "%s DefaultUserService.UpsertUserAttr err: req: %v  err: %v", fun, m, err)
		return nil, err
	}

	return res, nil
}
